#include <windows.h>
#include <string>
#include <vector>
#include <commctrl.h>

// 启动器界面选择
class UEStudioLauncher {
private:
    std::vector<std::string> themes = {
        "codeblocks-classic",
        "vscode-modern", 
        "vc2022-dark",
        "vc2022-light",
        "clion-inspired",
        "uestudio-original"
    };

public:
    void ShowLauncher() {
        // 创建启动器对话框
        CreateLauncherWindow();
    }
    
    void CreateLauncherWindow() {
        // 创建启动选择窗口
        HWND hWnd = CreateWindowEx(
            0, "STATIC", "UEStudio 启动器",
            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
            CW_USEDEFAULT, CW_USEDEFAULT, 600, 400,
            NULL, NULL, GetModuleHandle(NULL), NULL);
            
        // 添加主题选择按钮
        int y_pos = 50;
        for (const auto& theme : themes) {
            CreateWindow("BUTTON", theme.c_str(),
                        WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
                        50, y_pos, 200, 30, hWnd, 
                        (HMENU)(1000 + y_pos), NULL, NULL);
            y_pos += 40;
        }
        
        // 消息循环
        MSG msg;
        while (GetMessage(&msg, NULL, 0, 0)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    
    void LaunchWithTheme(const std::string& theme) {
        // 设置环境变量
        SetEnvironmentVariable("UESTUDIO_THEME", theme.c_str());
        
        // 启动主程序
        STARTUPINFO si = {sizeof(si)};
        PROCESS_INFORMATION pi;
        
        std::string cmd = "UEStudio.exe --theme=" + theme;
        
        if (CreateProcess(NULL, (LPSTR)cmd.c_str(), NULL, NULL, FALSE,
                         0, NULL, NULL, &si, &pi)) {
            WaitForSingleObject(pi.hProcess, INFINITE);
            CloseHandle(pi.hProcess);
            CloseHandle(pi.hThread);
        }
    }
};

// 启动器入口点
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                   LPSTR lpCmdLine, int nCmdShow) {
    UEStudioLauncher launcher;
    
    // 检查命令行参数
    if (strstr(lpCmdLine, "--theme=")) {
        // 直接启动指定主题
        std::string theme = strstr(lpCmdLine, "--theme=") + 8;
        launcher.LaunchWithTheme(theme);
    } else {
        // 显示启动器选择界面
        launcher.ShowLauncher();
    }
    
    return 0;
}
